using System;
using System.Collections.Generic;

namespace Servlets.Utils
{
	public static class CollectionUtils
	{
		/// <summary>
		/// Returns the value from the map with the given key or returns the given default value
		/// </summary>
		/// <param name="map">
		/// A <see cref="Dictionary<T, U>"/>
		/// </param>
		/// <param name="key">
		/// A <see cref="T"/>
		/// </param>
		/// <param name="defaultValue">
		/// A <see cref="U"/>
		/// </param>
		/// <returns>
		/// A <see cref="U"/>
		/// </returns>
		public static U GetOrDefault<T, U>(this Dictionary<T, U> map, T key, U defaultValue) {
			if(map.ContainsKey(key)) {
				return map[key];
			} else {
				return defaultValue;
			}
		}
	}
}

